{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import json\n",
    "import os\n",
    "import jieba\n",
    "from tqdm import tqdm\n",
    "import numpy as np\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                dialogue_idx  \\\n",
      "0  2022031511211002210107208   \n",
      "1  2022021317410449922313622   \n",
      "2  2022010119455307210193124   \n",
      "3  2022031811483274012548801   \n",
      "4  2022030519251399122147488   \n",
      "\n",
      "                                            dialogue  \\\n",
      "0  [{'speaker': '客服', 'text': '您好很高兴服务。', 'act': ...   \n",
      "1  [{'speaker': '客服', 'text': '您好很高兴为您服务。', 'act'...   \n",
      "2  [{'speaker': '客服', 'text': '您好很高兴为您服务。', 'act'...   \n",
      "3  [{'speaker': '客服', 'text': '你好请说你好。', 'act': '...   \n",
      "4  [{'speaker': '用户', 'text': '这个意思吗？', 'act': 'o...   \n",
      "\n",
      "                                              domain province  \n",
      "0  [{'name': '业务', 'type': '订购'}, {'name': '用户信息'...       北京  \n",
      "1  [{'name': '工单', 'type': '其他'}, {'name': '卡号', ...       浙江  \n",
      "2  [{'name': '套餐', 'type': '取消'}, {'name': '工单', ...       北京  \n",
      "3  [{'name': '宽带', 'type': '报修'}, {'name': '工单', ...       广东  \n",
      "4  [{'name': '其他', 'type': '报修'}, {'name': '工单', ...       江苏  \n"
     ]
    }
   ],
   "source": [
    "df = pd.read_json(\"../data/500.json\", dtype=\"string\")\n",
    "print(df.head())\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "ids = []\n",
    "for i in range(0, df.shape[0]):\n",
    "    logs = df4[df4.dialogue_idx == df.iloc[i].dialogue_idx].dialogue\n",
    "    domain = df3[df3.dialogue_idx == df.iloc[i].dialogue_idx].domain\n",
    "    ss = df5[df5.dialogue_idx == df.iloc[i].dialogue_idx].dialogue\n",
    "    if len(logs) == 0 or len(domain) == 0 or len(ss) == 0:\n",
    "        continue\n",
    "    else:\n",
    "        logs = logs.iloc[0]\n",
    "        domain = domain.iloc[0]\n",
    "        ss = ss.iloc[0]\n",
    "    df.iloc[i].domain = domain\n",
    "    ids.append(df.iloc[i].dialogue_idx)\n",
    "    for j in range(0, len(logs)):\n",
    "        df.iloc[i].dialogue[j]['act'] = logs[j]['act']\n",
    "        df.iloc[i].dialogue[j]['soothing_behavior'] = ss[j]['soothing_behavior']\n",
    "        df.iloc[i].dialogue[j]['sentiment'] = ss[j]['sentiment']\n",
    "df = df.loc[df.dialogue_idx.isin(ids)]\n",
    "print(df.shape)\n",
    "df.to_json(\"/root/data/labeled/2/all.json\", orient=\"records\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
